# @Author：silence
# @Email：792245022@qq.com
# @Date：2025/3/7 0:56

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

browser.get("https://www.baidu.com")

time.sleep(2)

input = browser.find_element(by=By.ID, value="kw")

# 在文本框中输入周杰伦
input.send_keys("周杰伦")

time.sleep(2)

button = browser.find_element(by=By.ID, value="su")

# 点击按钮
button.click()

# 滑到底部
js_bottom = "window.scrollTo(0, document.body.scrollHeight)"
# 执行脚本
browser.execute_script(js_bottom)

time.sleep(2)

next_button = browser.find_element(by=By.CSS_SELECTOR, value="a[class='n']")

next_button.click()

time.sleep(5)

# 回到上一页
browser.back()

time.sleep(5)

# 回去
browser.forward()

time.sleep(5)

# 退出
browser.quit()
